<template>
  <div class="step">
    <div class="email">
      <p>验证码</p>
      <input type="text" placeholder="请输入验证码" @focus="reset" v-model="code" @blue="verify"  v-bind:class="{ error: emailFlag }" />
      <div class="tips" >{{msg}}</div>
      <div class="next" @click="next">确定</div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      flag: true,
      msg: '',
      emailFlag: false,
      code: ''
    }
  },
  methods: {
    next () {
      this.verify()
      if (!this.emailFlag && this.code) {
        this.$store.dispatch('user/verifyCodeData', { email: sessionStorage.getItem('email'), code: this.code }).then(res => {
          // console.log(res)
          this.$emit('next')
        }).catch(res => {
          // console.log(res)
          this.emailFlag = true
          this.msg = res.message
        })
      }
      // this.$emit('next')
    },
    verify () {
      if (this.code === '') {
        this.msg = '请输入验证码'
        this.emailFlag = true
      } else {
        this.msg = ''
        this.emailFlag = false
      }
    },
    reset () {
      this.msg = ''
      this.emailFlag = false
    }
  }
}
</script>

<style lang="scss" scoped>
p {
   display: block;
  height: 22px;
  line-height: 22px;
  color: #3d4966;
  margin-bottom: 10px;
}
input {
  width: 360px;
  height: 44px;
  padding-left: 10px;
  opacity: 1;
  background: #ffffff;
  border: 1px solid #a5aebf;
  border-radius: 4px;

}
.next {
  width: 360px;
  height: 44px;
  opacity: 1;
  background: #304eec;
  border-radius: 4px;
  line-height: 44px;
  color: #ffffff;
  text-align: center;
}
.email {
  display: inline-block;
  margin-top: 272px;
  margin-left: 540px;
  .tips{
    height: 14px;
    margin-top: 8px;
    margin-bottom: 38px;
    color: #f05656;
  }
}
</style>
